package com.qkjia.zqkspringshell.gmallbean;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 **/
public class GlobalClass {

    private static GlobalClass singleObject=new GlobalClass();

    private static Map<String,Object> singleMap=new HashMap<>();

    private static Map<String, Object> paramsMap = new HashMap<>();
    private java.lang.Object Object;

    private GlobalClass()
    {
    }


    public static GlobalClass getGlobalClassInstance()
    {
        return singleObject;
    }


    //对象放属性
    public Object putParams(String name, Object value) {
        Object obj = paramsMap.get(name);
        singleMap.put(name, value);
        return Object;
    }

    //重置对象属性
    public Object removeParams() {
        paramsMap.remove("url");
        paramsMap.remove("driverClass");
        paramsMap.remove("sqlusername");
        paramsMap.remove("password");
        return paramsMap;
    }

    //放对象
    public boolean PutObjcet(String str,Object obj)
    {
        Object object=singleMap.get(str);
        if(object==null)
        {
            singleMap.put(str,obj);
            return true;
        }
        System.out.println("This Object is  already exist....");
        return false;
    }

    //获取对象
    public Object getObjcet(String str)
    {
        Object object=singleMap.get(str);
        if(object==null)
        {
            System.out.println("This Object is Not exsit...");
            return null;
        }
        return object;
    }


    //    移除对象
    public void RemoveObject(String str)
    {
        singleMap.remove(str);
    }

    //获取对象长度
    public int getObjceSize()
    {
        return singleMap.size();
    }

    //获取map对象
    public Map<String,Object> getMapObject()
    {
        return singleMap;
    }

    //监控全局的变量
    private final static List<Object> notifyList = new ArrayList<>();

    public void Notify() {
        //TODO
    }

    public boolean addNotfiyObject(Object object) {
        if (notifyList.contains(object)) {
            System.out.println("his Object is  already exist....");
            return false;
        }
        notifyList.add(object);
        return true;
    }

}
